﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NLBS.Data;
using NLBS.Entity;
using NLBS.Framework;
using NLBS.Resources;
using NLBS.Web;

namespace NLBS.Control
{
    
    public class PanelStatus : PanelModule
    {
        [TemplateContainer(typeof(DefaultCategoryTemplate))]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public override ITemplate ItemTemplate
        {
            get
            {
                return base.ItemTemplate;
            }
            set
            {
                base.ItemTemplate = value;
            }
        }

        public override string Title
        {
            get
            {
                return lang["stats"];
            }
            set
            {
                base.Title = value;
            }
        }

        protected override void CreateChildControls()
        {
            if (ItemTemplate == null)
                ItemTemplate = new DefaultStatusTemplate();
            base.CreateChildControls();
        }
    }

    public class DefaultStatusTemplate : ITemplate
    {
        public void InstantiateIn(System.Web.UI.Control container)
        {

            BlogInfo info = BlogInfo.Instance(); 
            container.Controls.Add(new LiteralControl(string.Format("{0}:{1}<br>",lang["articles"],info.ArticleCount)));
            container.Controls.Add(new LiteralControl(string.Format("<a href=\"#\" onclick=\"{2}\">{0}:{1}</a><br>", lang["comments"], info.CommentCount, UrlFormatsProvider.Instance().Comment())));
            //container.Controls.Add(new LiteralControl(string.Format("<a href=\"#\" onclick=\"{2}\">{0}:{1}</a><br>", lang["trackbacks"], info.PingTrackCount, "getCommonList('trackbacklist')")));
            container.Controls.Add(new LiteralControl(string.Format("<a href=\"#\" onclick=\"{2}\">{0}:{1}</a><br>", lang["reg_users"], info.UserCount, UrlFormatsProvider.Instance().UserList())));
            container.Controls.Add(new LiteralControl(string.Format("<a href=\"#\" onclick=\"{2}\">{0}:{1}</a><br>", lang["visitors"], HttpContext.Current.Application["TotalCount"].ToString(), UrlFormatsProvider.Instance().Visitors())));
            container.Controls.Add(new LiteralControl(string.Format("{0}:{1}<br><br>",lang["online_user"], HttpContext.Current.Application["OnLine"].ToString())));
            WriteRssImage(container, "feed.aspx", "Articles RSS Feed", "/styles/default/images/rss_article.png");
            //WriteRssImage(container, "feed.aspx?selected=true", "Selected Content RSS Feed", "/styles/default/images/rss_selected.png");
            //WriteRssImage(container, "feed.aspx?q=comment", "Comments RSS Feed", "/styles/default/images/rss_comment.png");
        }

        public Dictionary<string, string> lang
        {
            get
            {
                return Language.Instance().getLanguage();
            }
        }

        public void WriteRssImage(System.Web.UI.Control container,string url,string title,string image)
        {
            container.Controls.Add(new LiteralControl(string.Format("<a href=\"{0}\" title=\"{1}\" target=\"_blank\">", url,title)));
            container.Controls.Add(new LiteralControl(string.Format("<img src=\"{0}\" class=\"meta-button\" alt=\"{1}\" /></a><br />",RequestWrapper.ApplicationPath+image,title)));
        }

        private void writeFeed()
        {
            
    
        }
    }
}
